<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <style type="text/css">
        #divson {
            padding-top: 20px;
            padding-bottom: 20px;
            background-color: #D8D2D2;
        }

        .txt1 {
            font-size: 22px;
            color: white;
        }

        .list-group-item {
            border: 0px;
        }

        a {
            text-decoration: none
        }

        a:hover {
            text-decoration: none
        }

        a:link {
            color: #333 !important
        }

        a:hover {
            color: #2d58d3 !important
        }

        a:visited {
            color: #333 !important
        }
    </style>

    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/layui.css" />
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/common.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/slide.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/flat-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/jquery.nouislider.css">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/layui.js" media="all" ></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            $.ajax({
                type:"get",
                url:"${pageContext.request.contextPath }/admin/toTicket",
                dataType:"json",
                success:function(data){
                    console.log(data);
                    var tr="";
                    $.each(data, function(index,info) {
                       /* tr+="<tr><td>"+info.ticketId+"</td><td>"+info.tiType+"</td>"+ "<td><button class='btn btn-danger btn-xs ' data-toggle='modal'  value='"+info.ticketId+" ' id='del'><i class='glyphicon glyphicon-remove'></i>删除</button></td></tr>";*/
                        tr+="<tr><td>"+info.ticketId+"</td><td>"+info.tiType+"</td>"+
                            "<td><button id='updateTiceket' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateTicket' value='"+info.ticketId+" '>修改</button>"+
                            "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.ticketId+" 'id='del'>删除</button></td><tr/>";

                    });
                    $("#table-listS").html(tr);


                }
            });

            // 关键字搜索
            $("#search").click(function () {
                $.ajax({
                    type: "get",
                    url: "${pageContext.request.contextPath}/admin/adminByTicket",
                    dataType: "json",
                    data: {
                        keyword: $("#keyword").val()
                    },
                    success: function (data) {
                        if (data != "") {
                            var tr = "";
                            $.each(data, function (index, info) {

                                tr+="<tr><td>"+info.ticketId+"</td><td>"+info.tiType+"</td>"+
                                    "<td><button id='updateTicket' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateTickets' value='"+info.ticketId+" '>修改</button>"+
                                    "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.ticketId+" 'id='del'>删除</button></td><tr/>";

                            });
                            $("#table-listS").html(tr);
                        }else {
                            alert("没有该电影类别");
                        }

                    }

                })

            });

            //删除
            $("#table-listS").on("click", "#del", function() {
                console.log($(this).val())
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/ticDel",
                    data:{
                        ticketId:$(this).val()
                    },
                    dataType:"json",
                    success:function(data){
                        if (data==1){
                            alert("删除成功")
                        }else {
                            alert("删除失败")
                        }
                        window.location.reload();
                    }
                });

            });



            $("#table-listS").on("click", "#updateTicket", function() {
                $("#ticketId").val($(this).closest("tr").find("td").eq(0).text())
                $("#tiType").val($(this).closest("tr").find("td").eq(1).text())




            });


            $("#doTiceket").click(function () {
                console.log($("#ticketId").val());
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/doTicketUpdate",
                    data:{
                        ticketId:$("#ticketId").val(),
                        tiType:$("#tiType").val()

                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        if (data!=null){
                            alert("修改成功");
                            window.location.href = "${pageContext.request.contextPath}/ticket";
                        }
                    }
                });
            });

            $("#adTiceket").click(function(){
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}admin/addTicket",
                    dataType:"text",
                    data:{
                        ticketId:$("#ticketId").val(),
                        tiType:$("#tiTypes").val()
                    },
                    success:function(data){
                        if (data==1) {
                            alert("添加成功");
                            location.href="${pageContext.request.contextPath}/ticket";
                        }
                    }, error:function(){
                        alert("系统崩溃！");
                    }
                });
            })




        });
    </script>
</head>
<body>
<!--地区管理模块-->
<div role="tabpanel" class="tab-pane" id="scho">

    <div class="check-div form-inline">
        <div class="col-xs-3" style="padding-top: 25px">
            <button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#addTiceket">添加票 </button>
        </div>
        <div class="col-lg-4 col-xs-5">
            <input type="text" class=" form-control input-sm " placeholder="输入文字搜索" id="keyword">
            <button class="btn btn-white btn-xs " id="search">查 询 </button>
        </div>

    </div>

            <table  class="table text-center" id="tab">

                <thead>
                <tr>
                    <th class="text-center">编号</th>
                    <th class="text-center">类别</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="table-listS">

                </tbody>

            </table>

        </div>


<!--修改用户弹出窗口-->
<div class="modal fade" id="updateTickets" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">修改票务信息</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="songId"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-3 control-label">票务类别：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="tiType" class="form-control input-sm duiqi" id="sName" placeholder="">
                            </div>
                        </div>

                    </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-green" id="doTiceket">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

</div>



<!--增加权限弹出窗口-->
<div class="modal fade" id="addTiceket" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">添加票务</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="songIds"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-3 control-label">票务类别：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="tiTypes" class="form-control input-sm duiqi" id="sName" placeholder="">
                            </div>
                        </div>

                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-green"  id="adTiceket">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

</body>
</html>
